package com.ftg.midamall.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ftg.midamall.comm.vo.CodeStatusEnum;
import com.ftg.midamall.comm.vo.RespMessUtil;
import com.ftg.midamall.entity.PmsProduct;
import com.ftg.midamall.mapper.PmsProductMapper;
import com.ftg.midamall.service.IPmsProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 商品信息 服务实现类
 * </p>
 *
 * @author wrn
 * @since 2023-10-25
 */
@Service
public class PmsProductServiceImpl extends ServiceImpl<PmsProductMapper, PmsProduct> implements IPmsProductService {

    @Resource
    PmsProductMapper pmsProductMapper;

    @Override
    public RespMessUtil<IPage> showAllWithPage(long pageSize, long pageLimit, String goodsName) {
        IPage<PmsProduct> ipage = new Page<>(pageSize, pageLimit);
        QueryWrapper<PmsProduct> query = new QueryWrapper<>();
        if (!StrUtil.isBlank(goodsName)) {
            query.like("name", goodsName);
        }
        return RespMessUtil.build(CodeStatusEnum.SUCCESS, this.getBaseMapper().selectPage(ipage, query));
    }

    @Override
    public Integer insertgoods(PmsProduct pp) {
        return pmsProductMapper.insert(pp);
    }

    @Override
    public Integer deletegoods(Long id) {
        return pmsProductMapper.deleteById(id);
    }

    @Override
    public Integer deleteBatchByIds(List<Long> ids) {
        return pmsProductMapper.deleteBatchIds(ids);
    }

    @Override
    public Integer updategoods(PmsProduct pp) {
        return pmsProductMapper.updateById(pp);
    }


}
